package com.sali.netty.handler;

import com.sali.netty.NettyClient;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

/**
 * @description:
 * @author: sali
 * @date: 2025/2/22 下午11:15.
 * @version: 1.0
 */
public class ClientHandleInitializer extends ChannelInitializer<NioSocketChannel> {

    private NettyClient client;

    public ClientHandleInitializer(NettyClient client) {
        this.client = client;
    }

    @Override
    protected void initChannel(NioSocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new StringDecoder())
                .addLast(new StringEncoder())
                .addLast(new ClientChannelHandler(client));
    }

}
